<HTML>

<HEAD>
</HEAD>
<TITLE> OGRE tutorial.
</TITLE>
<BODY>

<H2 ALIGN=CENTER > Tutorial: Exporting meshes from 3dsmax 5</H2>


This tutorial shows how to export a skateboard from 3D studio Max 5. You will export a mesh made up of several submeshes and
its assigned material.

<H4> Introduction </H4>
First, open the file "skateboard_1.max" that you can find in this <A href=skateboard_1.zip>zip file</A>.<BR>
<B>Copy the png file to "C:\" directory or change the path in the material editor. You should also copy it to your OGRE Media directory.</B><BR>
You can see 2 boards which have been cloned. They are made up of a board that have been mapped with <I>UVW unwrap</I>,
4 wheels and 2 trucks.<BR>

<img src="images/intro1.jpg" /> <img src="images/intro2.jpg" /> <BR>


<H4> Create one object with submeshes</H4>

<UL>
   <LI> Select the board (whose name is "board") which is at (0,0,0) and convert it to an editable mesh.
        Attach the wheels and the trucks.<BR><BR>
   </LI>
   
   <LI> As you can see, texture mapping has changed, we must create a MultiMaterial and assign material ids to submeshes.
        In the material editor (press "M"), assign the multiMaterial to the board, and in the element subobject mode,
        choose material Id 1 for the board, 2 for the wheels and 3 for the trucks.<BR>
        <img src="images/assignIds.jpg" />
        <BR> 
        <BR><BR>
   </LI>
   <LI> That's all, the mesh is ready to be exported. </LI>
</UL>

<H4> Run the mesh exporter</H4>

The script allows you to run XMLConverter after exporting. This is set in the OgreScript.ini file.
Here is an example:
<PRE>
      [Directories]
      XMLConverterPath=e:\C++\ogrenew\Tools\XMLConverter\bin\Debug
      MediaPath=E:\C++\ogrenew\Samples\Media
      
      [Exe]
      XMLConverterExe=OgreXMLconverter.exe
      
      [Settings]
      lastFile=e:\C++\ogrenew\Tools\XMLConverter\bin\Debug\bbb
      lastAnimName=walk
      lastMaterialFile=E:\C++\ogrenew\Samples\Media\3ds.material
      
      [Tools]
      runXMLConverter=no
</PRE>

As you can see, settings are saved, so you avoid to write again and again the same output files and animation name.
To be able to run XMLConverter, change the last line as:
<PRE>
   runXMLConverter=yes
</PRE>
and set up your directories. 
<B>Nota:</B>you may have to change XMLConverterExe to another name (to the former XMLConverter), there will not be any warnings if a path or the exe file contains errors. <BR>
<BR>
Now choose the board, check the "export mesh" checkbox and press the export button.<BR><BR>
<B>Nota: Using the log - When there is no submesh: </B>
Open the Maxscript Listener ("MaxScript/Maxscript Listener" or "F11"), You should see a log.
You should verify that there is the number of submeshes you expect, <U>especially when you have not
any submesh</U>. 3dsmax sets 6 material Id when a mesh is created, I think. So if you see lots of submeshes,
just set the material ID in subobject mode.
<BR><BR>


<B>Nota: material names : </B>
As you can see if you open the .mesh.xml file which has been written, submesh material names are materialname/* 
where * is a sub material name. If you forget this, you may have an "material not found" error at runtime.<BR>

So our materials are called: skateboard_board/board, skateboard_board/wheels, skateboard_board/trucks.

Here is the material file you have to write (in any .material file in the Media directory)
<PRE>
material skateboard_board/board_#132
{
    technique
    {
        pass
        {
            ambient 0.588 0.588 0.588
            diffuse 0.588 0.588 0.588
            specular 0.9 0.9 0.9 0.0
            emissive 0.0 0.0 0.0
            texture_unit
            {
                texture skateboard.png 
            }
        }
    }
}

material skateboard_board/wheels
{
    technique
    {
        pass
        {
            ambient 0.796079 0.780392 0.588235
            diffuse 0.796079 0.780392 0.588235
            specular 0.9 0.9 0.9 0.0
            emissive 0.0 0.0 0.0
        }
    }
}

material skateboard_board/trucks
{
    technique
    {
        pass
        {
            ambient 0.737255 0.737255 0.737255
            diffuse 0.737255 0.737255 0.737255
            specular 0.9 0.9 0.9 0.0
            emissive 0.0 0.0 0.0
        }
    }
}
</PRE>

But, read the next section before doing this ;) .

<H4> Run the material exporter</H4>

No run the material exporter in the Ogre Toolbar. (If you don't find the material exporter button, have a look 
<A href="../ToolBar/index.html">here</A>) <BR>It can only (but it's sufficient) export MultiMaterials and Standard Materials.

<UL>
<LI> It adds /* to material names. </LI>
<LI> It retrieves the Diffuse map of submaterials, or if it is undefined, it uses ambient, diffuse, etc. colors.</LI>
</UL>

You should see the following window: <BR>
<img src="images/materialtools.jpg" /> <BR>
<BR>
Click on "Pick material", choose Scene in the right panel, and choose the snowboard_board material.<BR>
<img src="images/choosemultimaterial.jpg" /> <BR>

Click on 'Ok' button in order to select the material you want to export.<BR>

Select instance in the popup, <BR>
Choose an output filename (in the OGRE Media directory), <BR>
Press the Export button. <BR>
<BR>
There is an other button which allow you to export all the materials used in the scene.<BR>

<BR><B> That's all ! Have fun with this exporter !</B><BR><BR>

<CENTER>
<A href="../../index.html">Return to homepage</A>
</CENTER>
<BR>
<BR>
If you have seen any errors or have any suggestions, mail me at mallard@iie.cnam.fr.

</BODY>
</HTML>